{template /common/header}
  <!-- S 当前价 -->
  <ul class="flex ykj_current_price">
    <li class="art_left">
      <ul>
        <li>当前价</li>
        <li><span class="big"><?php echo $today['price']?></span>$</li>
        <li>≈<?php echo bcmul($today['price'],C("site_cny_usd"),4);?>CNY</li>
      </ul>
    </li>
    <li class="art_right">
      <ul>
        <li>最高：<?php echo $today['max_price']?>$</li>
        <li>最低：<?php echo $today['min_price']?>$</li>
        <li>幅：<?php echo $range;?>%</li>
      </ul>
    </li>
  </ul>
  <ul class="flex ykj_order_count">
    <li>当前求购订单量：<?php echo (int)$buy_order_count;?> </li>
    <li>当前出售订单量：<?php echo (int)$sell_order_count;?> </li>
  </ul>
  <!-- E 当前价 -->
  <!-- S DBT价格线 -->
  <div class="ykj_price_line">
    <p class="title">DBT价格线</p>
    <script src="https://img.hcharts.cn/highcharts/highcharts.js"></script>
    <script src="https://img.hcharts.cn/highcharts/modules/exporting.js"></script>
    <script src="https://img.hcharts.cn/highcharts-plugins/highcharts-zh_CN.js"></script>
    <div class="index-chart">
    <div id="container" style="height:200px;min-width:300px"></div>
    </div>
  </div>

  
  <!-- E DBT价格线 -->
  <!-- S 买入卖出 -->
  <ul class="dbt_business">
    <li class="flex flex-pack-justify">
      <label class="label">单价</label>
      <div class="alignR">
        <i class="minus iconfont" id="priceDec">&#xe68e;</i>
        <input type="text" name="price" id="price" class="input_box">
        <i class="plus iconfont" id="priceInc">&#xe623;</i>
      </div>
    </li>
    <li class="flex flex-pack-justify">
      <label class="label">数量</label>
      <div class="alignR">
        <i class="minus iconfont" id="numDec">&#xe68e;</i>
        <input type="text"  name="num" id="num"  class="input_box">
        <i class="plus iconfont" id="numInc">&#xe623;</i>
      </div>
    </li>
    <li class="flex flex-pack-justify dbt_antipate">
      <div>预计收入：<span class="red" id="sr" >0.00</span></div>
      <div>可用<span class="red" id="user_money">0</span>DBT</div>
    </li>
    <li class="flex flex-pack-justify">
      <a href="javascript:;" class="saleBtn" onclick="dosell();">卖出</a>
      <a href="javascript:;" class="buyBtn" onclick="dobuy();">买入</a>
    </li>
  </ul>
  <!-- E 买入卖出 -->
  <!-- S 列表 -->
  <div class="dbt_lists">
    <ul class="flex flex-pack-justify dbt_tab_title">
      <li data-type="2" class="cur"><a href="javascript:void(0);">求购列表</a></li>
      <li data-type="1" ><a href="javascript:void(0);">出售列表</a></li>
    </ul>
    <div class="dbt_tab_content">
      <div class="dbt_tab_item">
        <div class="searchBox">
          <input type="text" placeholder="请输入对方手机号查找" class="input_search" id="phone">
          <i class="iconfont">&#xe65f;</i>
        </div>
        <ul id="listcon">
        </ul>
      </div>
    </div>
  </div>
<div class="popup_shade"></div>
<div class="affirm_popUp">
  <dl class="title">
    <dt>请输入确认短信验证码</dt>
    <dd><?php echo $this->userinfo['mobile_phone']?></dd>
  </dl>
  <div class="flex my_get_code">
    <input type="text" placeholder="请输入短信验证码" id="code_num" class="code_input">
    <a href="javascript:;" class="yzm send_code">获取验证码</a>
  </div>
  <ul class="evaluate_btn_box flex flex-pack-justify">
    <li><a href="javascript:;" class="btn btn1" onclick="closePop();">取消</a></li>
    <li><a href="javascript:;" class="btn btn2" onclick="act_fun(act_type)" >完成</a></li>
  </ul>
</div>
<script type="text/html" id="list_model">
<% if(list.length >0){%>
    <% for (var k in list) { var v = list[k]; %>
          <li class="dbt_tab_item_li" id="item_<%=v.id%>" data-num="<%=v.num%>" >
            <div class="dbt_user_info"><img src="<%=v.ico%>" alt="" width="40" class="dbt_user_img"><span class="dbt_user_name"><%=v.username%></span></div>
            <div class="flex flex-pack-justify dbt_cny_box">
              <dl>
                <dt class="red font24 bold"><%=v.cny%></dt>
                <dd class="color888">价格(CNY）</dd>
              </dl>
              <dl class="alignC">
                <dt class="font24 bold"><%=v.num%></dt>
                <dd>DBT数量</dd>
              </dl>
              <% if(v.type==1){%><a href="javascript:;" class="sellBtn" onclick="buyer(<%=v.id%>)">购买</a><%}%>
              <% if(v.type==2){%><a href="javascript:;" class="sellBtn" onclick="seller(<%=v.id%>)">出售</a><%}%>
            </div>
            <div class="flex dbt_deal_info">
              <ul>
                <li>
                  <label>单价<i></i></label>
                  <span><%=v.price%>$</span>
                </li>
                <li>
                  <label>成交量</label>
                  <span><%=v.order_num%></span>
                </li>
              </ul>
              <ul>
                <li>
                  <label>总价</label>
                  <span><%=v.amount%>¥</span>
                </li>
                <li>
                  <label>好评率</label>
                  <span><%=v.order_appr%>%</span>
                </li>
              </ul>
            </div>
          </li>
    <%}%>
    <li class="loading"><div class="spinner"><i></i></div>数据读取中</li>
<%  } %>
</script>
<script type="text/javascript" src="{THEME_PATH}js/template.js"></script>
<script type="text/javascript" src="{THEME_PATH}js/ncscroll-load.js"></script>
<script>
var type =2;
var phone = "";
var pagesize = 10;
//渲染list
var load_class = new ncScrollLoad();
load_class.loadInit({'url':'/index.php?m=goods&c=trade&a=tradelist','getparam':{'type':type,'phone':phone},'tmplid':'list_model','containerobj':$("#listcon"),'iIntervalId':true});
    function tab(menus, conts) {
        $(menus).click(function() {
            var index = $(this).index();
                $(this).addClass("cur").siblings().removeClass("cur");
                console.log($(this).data("type"));
                type = $(this).data("type");
                // $("#listcon").html("");
                load_class.loadInit({
                  'url':'/index.php?m=goods&c=trade&a=tradelist',
                  'getparam':{'type':type},
                  'tmplid':'list_model',
                  'containerobj':$("#listcon"),
                  'iIntervalId':true
                });
              $(conts).eq(index).removeClass("hide").siblings().addClass("hide");
        })
    }
    tab(".dbt_tab_title li", ".dbt_tab_content .dbt_tab_item")
$("#phone").bind("input propertychange",function(){
  phone = $(this).val();
  if(isPoneAvailable(phone)){
    $("#listcon").html("");
    load_class.loadInit({
      'url':'/index.php?m=goods&c=trade&a=tradelist',
      'getparam':{'type':2,'phone':phone},
      'tmplid':'list_model',
      'containerobj':$("#listcon"),
      'iIntervalId':true
    });
  }
  if(phone==""){
    $("#listcon").html("");
    load_class.loadInit({
      'url':'/index.php?m=goods&c=trade&a=tradelist',
      'getparam':{'type':2,'phone':phone},
      'tmplid':'list_model',
      'containerobj':$("#listcon"),
      'iIntervalId':true
    });
  } 
})
    function isPoneAvailable(phonenumber) {
        var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
        if (!myreg.test(phonenumber)) {
            return false;
        } else {
            return true;
        }
    }
</script>
  <script>
    // 曲线图
    var sell_days = <?php echo json_encode($sell_days) ?>;
    var serdata  = <?php echo json_encode($series); ?>;
    var chart = Highcharts.chart('container',{
        chart: {
            type: 'area'
        },
        credits:{
            enabled: false // 禁用版权信息
        },
        exporting:{
             enabled: false // 禁用到处模块
        },
        legend: {
            enabled:false,
            layout: 'vertical',
            align: 'center',
            verticalAlign: 'top',
            x: 0,
            floating: true,
            //borderWidth: 1,
            backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
        },
        title: {
            text: ''
        },
        xAxis: {
            allowDecimals: false,
            categories: sell_days,
        },
        yAxis: {
            title: {
                text: ''
            }
        },
        tooltip: {
            pointFormat: '{series.name}<b>{point.y}</b>'
        },
        plotOptions: {
            area: {
                fillOpacity: 0.3
            }
        },
        series:serdata
    });


<?php 
  $userinfo = getUserInfo();
  //p($userinfo);
?>
var tradeok="<?php echo $userinfo['is_renzheng'];?>";

    function checkSr(){
        var price = parseFloat($("#price").val());
        var num = parseFloat($("#num").val());
        if(price=="" || isNaN(price)) price=0;
        if(num=="" || isNaN(num)) num=0;
        $("#sr").html(parseFloat(price*num).toFixed(2)); 
    }
    $(function(){
        $("#numDec").click(function(){
            var num = parseFloat($("#num").val());
            if(num=="" || isNaN(num)) num=0;
            var newNum = num-1;
            if(newNum<0) newNum=0;
            $("#num").val(newNum);
            checkSr();
        })
        $("#numInc").click(function(){
            var num = parseFloat($("#num").val());
            if(num=="" || isNaN(num)) num=0;
            $("#num").val(num+1);
            checkSr();
        })
        $("#priceDec").click(function(){
            var price = parseFloat($("#price").val());
            if(price=="" || isNaN(price)) price=0;
            var newPrice = price-1;
            if(newPrice<0) newPrice=0;
            $("#price").val(newPrice);
            checkSr();
        })
        $("#priceInc").click(function(){
            var price = parseFloat($("#price").val());
            if(price=="" || isNaN(price)) price=0;
            $("#price").val(price+1);
            checkSr();
        })
        $("#price").bind("input propertychange",function(){
          var price = parseFloat($("#price").val());
          var num = parseFloat($("#num").val());
          if(price=="" || isNaN(price)) price=0;
          if(num=="" || isNaN(num)) num=0;
          $("#sr").html(parseFloat(price*num).toFixed(2));
        });
        $("#num").bind("input propertychange",function(){
          var price = parseFloat($("#price").val());
          var num = parseFloat($("#num").val());
          if(price=="" || isNaN(price)) price=0;
          if(num=="" || isNaN(num)) num=0;
          $("#sr").html(parseFloat(price*num).toFixed(2));
        });
    })
    var act_type=0;
    function dosell(){
          act_type = 1;
          var price = parseFloat($("#price").val());
          var num = parseFloat($("#num").val());
          if(price=="" || isNaN(price)) price=0;
          if(num=="" || isNaN(num)) num=0;
          if(price==0){
            tips("请输入单价！");
            return;
          }
          if(num==0){
            tips("请输入交易数量！");
            return;
          }
          layer.open({
            content: '是否要卖出'+num+' DBT'
            ,btn: ['确定', '取消']
            ,yes: function(index){
              layer.close(index);

              if(!tradeok){
                hd_alert("未实名，无法进行此操作");
                return false;
              }
              $(".popup_shade,.affirm_popUp").show();
            }
          });
    }
    // 卖出
    function dosell1(){
      var price = parseFloat($("#price").val());
      var num = parseFloat($("#num").val());
      if(price=="" || isNaN(price)) price=0;
      if(num=="" || isNaN(num)) num=0;
      if(price==0){
        tips("请输入单价！");
        return;
      }
      if(num==0){
        tips("请输入交易数量！");
        return;
      }
      console.log(price);
      console.log(num);
      var type=1;


       var code_num =$("#code_num").val();
      $("#code_num").val("");
      $(".popup_shade,.affirm_popUp").hide();     
      // layer.open({
      //   content: '是否要卖出'+num+' DBT'
      //   ,btn: ['确定', '取消']
      //   ,yes: function(index){
      //     layer.close(index);
          $.ajax({
            type:'post',
            url:'/index.php?m=user&c=trade&a=doact',
            data:{price:price,num:num,type:type,code_num:code_num},
            dataType:'json',
            success:function(ret){
              layer.closeAll();
              console.log(ret);
              if(ret.status==1){
                  tips(ret.info,'/index.php?m=goods&c=trade&a=index');
              }else{
                  hd_alert(ret.info);
              }
            }
          })
      //   }
      // });
    }

  function dobuy(){
        act_type = 2;
        var price = parseFloat($("#price").val());
        var num = parseFloat($("#num").val());
        if(price=="" || isNaN(price)) price=0;
        if(num=="" || isNaN(num)) num=0;
        if(price==0){
          tips("请输入单价！");
          return;
        }
        if(num==0){
          tips("请输入交易数量！");
          return;
        }
        layer.open({
          content: '是否要买入'+num+' DBT'
          ,btn: ['确定', '取消']
          ,yes: function(index){
            layer.close(index);
            if(!tradeok){
              hd_alert("未实名，无法进行此操作");
              return false;
            }
            $(".popup_shade,.affirm_popUp").show();

          }
        });
  }



    // 买入
    function dobuy1(){
      var price = parseFloat($("#price").val());
      var num = parseFloat($("#num").val());
      if(price=="" || isNaN(price)) price=0;
      if(num=="" || isNaN(num)) num=0;
      if(price==0){
        tips("请输入单价！");
        return;
      }
      if(num==0){
        tips("请输入交易数量！");
        return;
      }
      console.log(price);
      console.log(num);
      var type=2;

      var code_num =$("#code_num").val();
      $("#code_num").val("");
      $(".popup_shade,.affirm_popUp").hide();



      // layer.open({
      //   content: '是否要买入'+num+' DBT'
      //   ,btn: ['确定', '取消']
      //   ,yes: function(index){
      //     layer.close(index);
          $.ajax({
            type:'post',
            url:'/index.php?m=user&c=trade&a=doact',
            data:{price:price,num:num,type:type,code_num:code_num},
            dataType:'json',
            success:function(ret){
              layer.closeAll();
              console.log(ret);
              if(ret.status==1){
                  tips(ret.info,'/index.php?m=goods&c=trade&a=index');
              }else{
                  hd_alert(ret.info);
              }
            }
          })
      //   }
      // });
    }
    // 购买
    function buyer(id){
      return;
      // $.ajax({
      //   type:'post',
      //   url:'/index.php?m=user&c=trade&a=dobuyer',
      //   data:{id:id},
      //   dataType:'json',
      //   success:function(ret){
      //     layer.closeAll();
      //     console.log(ret);
      //     if(ret.status==1){
      //       tips(ret.info);
      //         // window.location.href='/index.php?m=user&c=order&a=buyok&order_sn='+ret.oid;
      //     }else{
      //         tips(ret.info);
      //     }
      //   }
      // })
      // console.log(id);
    }
    var tid = 0;
    // 出售
    function seller(id){
      act_type = 3;
      tid=id;
      layer.open({
        content: '是否要出售'+$("#item_"+id).data("num")+' DBT'
        ,btn: ['确定', '取消']
        ,yes: function(index){
          layer.close(index);
          if(!tradeok){
            hd_alert("未实名，无法进行此操作");
            return false;
          }
          $(".popup_shade,.affirm_popUp").show();
        }
      });
    }
    function act_fun(act_type){
      if(act_type==1) dosell1();
      if(act_type==2) dobuy1();
      if(act_type==3) seller1();
    }
    function seller1(){
      var code_num =$("#code_num").val();
      $("#code_num").val("");
      $(".popup_shade,.affirm_popUp").hide();
      $.ajax({
        type:'post',
        url:'/index.php?m=user&c=trade&a=doseller',
        data:{id:tid,code_num:code_num},
        dataType:'json',
        success:function(ret){
          layer.closeAll();
          console.log(ret);
          tips(ret.info);
              if(ret.status==1){
                  tips(ret.info,'/index.php?m=goods&c=trade&a=index');
              }else{
                  hd_alert(ret.info);
              }
        }
      })
    }
    function closePop(){
      $(".popup_shade,.affirm_popUp").hide();
    }


$(function(){
    $(".send_code").click(function(){
      console.log(1);
        var text=$(this).text();
        var type=$(this).attr("type");
        if(text!="获取验证码"){
            return false;
        }
        console.log(2);

    $.ajax({
      url: "{U('User/Public/send_code')}&token={$_SESSION['send_code_time']}&type=trade",
      timeout: 5000,cache: false,type: "get",async : false,dataType: "json",
      success: function (d){
        if(d.status==1){
           downtime(120);
        }
        tips(d.info);
      }
    });
    })
})
/**
* 验证码倒计时
* time 倒计时时间：秒
**/
function downtime(time){
  //循环调用
  if(time == '0'){
    $('.send_code').text('获取验证码');
  }else{
    time --;
    $('.send_code').text('重新发送('+time+')');
    setTimeout(function() {
    downtime(time);
    },1000);
  }
}
</script>







  </script>
    {template /common/footer}